package wwy.Controller;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import wwy.Dto.LoginDto;
import wwy.Dto.UserDto;
import wwy.feign.getUserService;

@RestController
@Tag(name = "登录")
@RefreshScope
public class LoginController {
    @Resource
    private getUserService serviceInstance;

    @PostMapping("/login")
    @LoadBalanced
    @CircuitBreaker(name="backendA" ,fallbackMethod = "loginFallback")
    public UserDto login(@RequestBody LoginDto loginDto){
        return serviceInstance.getUserInfo(loginDto);
    }

    public UserDto loginFallback(LoginDto loginDto, Throwable throwable){
        System.out.println(loginDto.getPhone()+"登陆失败" + throwable.getMessage());
        return null;
    }

}
